package com.glut.campusrepair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.glut.campusrepair.service.IFailureRepairPostService;
import com.glut.campusrepair.entity.FailureRepair;
import com.glut.campusrepair.mapper.FailureRepairPostMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 *  服务实现类
 *
 * @author stubborn
 * @since 2024-07-20 15:08
 */
@Service
public class FailureRepairPostServiceImpl extends ServiceImpl<FailureRepairPostMapper, FailureRepair> implements IFailureRepairPostService {
    @Autowired
    FailureRepairPostMapper failureRepairPostMapper;

    @Override
    public List<FailureRepair> selectAll() {
        return list(); // 使用MyBatis-Plus提供的list()方法查询所有记录
    }

    @Override
    public List<FailureRepair> selectByUserNo(String userNo) {
        LambdaQueryWrapper<FailureRepair> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FailureRepair::getUserNo, userNo);
        return list(queryWrapper);
    }
    @Override
    @Transactional
    public boolean updateFailureRepair(FailureRepair failureRepair) {
        failureRepair.setUpdateTime(new Date());
        return updateById(failureRepair);
    }

    @Override
    @Transactional
    public boolean deleteFailureRepair(Integer id) {
        return removeById(id);
    }

}
